Skip to content

fix(agents): the wake sweep no longer forks sessions owned by a disconnected SSH pane or a stale-workspace record - #29454

Merged
nwparker merged 9 commits into
mainfrom
nwparker/wake-sweep-cross-worktree-claims
Oct 16, 2026
Merged

nwparker merged 9 commits into
mainfrom
nwparker/wake-sweep-cross-worktree-claims

Conversation

@nwparker

@nwparker nwparker commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​301 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​301
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​147 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​143

ELI5

When you switch back to a workspace, Orca resumes any agent sessions that were asleep there. Before resuming one, it checks whether some terminal pane already owns that conversation. In three cases the check got it wrong and decided nobody owned it. Orca then opened a new tab running a second claude --resume on the same transcript. We've seen up to five copies of one session, each leaving an orphan tab and an orphan remote terminal.

This takes over #12702 by @robertnisipeanu (rebased onto current main, with one review fix added) and supersedes it.

What Changed

All changes are in the wake sweep (resumeSleepingAgentSessionsForWorktree) and its pane-ownership check (recordPaneIsOwnedByPreservedPane).

  1. An SSH pane whose host is unreachable. When the connection drops, Orca clears its live-terminal map for that host, but the remote agent keeps running. The pane's saved layout still names the SSH terminal. Before: the pane looked dead and got a duplicate resume. After: a pane bound to an SSH terminal whose target isn't connected still owns its session, because losing contact is unverifiable, not exited. Once the target is connected, the live map decides again, so a workspace the user put to sleep still resumes. In a split, the tab-level terminal is only used as a fallback for a single-pane tab, so one pane is never credited with another pane's terminal. Main's workspace-level unverifiable guard (STA-3500) already declines the whole sweep for a disconnected SSH workspace. This adds the same verdict per pane, for tabs that the stale-workspace lookup in item 2 now finds.
  2. A record pointing at the wrong workspace. A sleeping record stores the workspace it saw at capture time, and that can go stale, for example with an agent-managed checkout. Before: the tab lookup only searched that one workspace, missed the tab, and relaunched. After: tab ids are globally unique, so the lookup falls back to a global scan, the same approach ai-vault-original-pane.ts uses.
  3. Duplicates across workspaces. The duplicate check is keyed per workspace, so two records for the same conversation under different workspace ids never collided. After: before launching, the sweep checks whether a pane anywhere already owns the same provider session. If one does, it clears the stale record and launches nothing. Finished notes never count as a claim. Neither does a record whose workspace now routes to another execution host, or a record that names a different machine than the one being resumed (the Codex findings below).

Why

Each fix extends the existing ownership predicate and sweep rather than adding a parallel mechanism.

Alternatives considered:

  • Dropping worktreeId from the claim key. That changes the dedupe for every caller, including the activation gate and the skip-claim plumbing, which is a much wider change than an explicit cross-workspace check in the one place that launches.
  • Rewriting stale worktreeIds on records. That's a migration with its own risks, and it doesn't help records captured later.

Linked Issue

Linear STA-3498. Supersedes #12702.

Visual Proof

N/A. This fixes a duplicate tab and process that appeared after a reconnect or workspace switch. Nothing new is rendered.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated: src/renderer/src/lib/resume-sleeping-agent-session-live-ssh-dedupe.test.ts (10 tests). The tests for the disconnected SSH pane, the stale workspace id, and the cross-workspace claim fail on main and pass here. The moved-host, folder-workspace and different-machine cases each fail without their review fix.

Review

Codex review (gpt-6.1-sol, high):

  • Round 1, P2: a record in another workspace whose host had moved could claim the session. That deleted the only record able to resume it. Fixed: the claiming record must pass the existing sleepingRecordNamesAnotherExecutionHost guard.
  • Round 2, P2: matching session ids on two different machines (for example a copied agent state directory) counted as one session. Fixed: a claim is accepted only when the two records don't positively name different machines.
  • Round 3, P2: the machine comparison needed both records to carry the same kind of evidence. Fixed: each record's machine is now resolved independently, from its catalog host or else its SSH capture stamp.
  • Round 4: no findings. CI's focus-read ratchet then rejected the catalog resolver the round 1-3 fixes used, because it reads the focused-server routing default. The comparison now reads only each record's own owner rows (worktree host, repo, or folder workspace and its project group), with no routing default.
  • Round 5, P2: folder workspaces weren't resolved, so a folder record whose host had moved could still claim the session. Fixed and tested.
  • Round 6, P2, dismissed under the review cap (after round 4, only P0/P1 get fixed): when the active workspace's selected host disagrees with its own catalog row, the owner-row check can miss the claimant's move. Handling it needs the focus-aware resolver the ratchet forbids here. The case also needs a matching session id in a second workspace plus a stale pane binding, and the worst outcome is a lost automatic wake, never a forked transcript.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • SSH: verdicts stay live / unverifiable / exited. A disconnected target is never treated as proof that the agent died.
  • Folder workspaces: the lookup is by tab id and doesn't assume git.
  • This is renderer-only, so there's no wire change.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 5 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 16fac31d-ac9f-4869-9657-b990c658e720
📥 Commits

Reviewing files that changed from the base of the PR and between 861d6250228126ae8336e643b047cc0ce2b4bf14 and d01252e.

📒 Files selected for processing: 3
  • src/renderer/src/lib/resume-sleeping-agent-session-live-ssh-dedupe.test.ts
  • src/renderer/src/lib/resume-sleeping-agent-session.ts
  • src/renderer/src/lib/sleeping-record-execution-host-scope.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 82f6004d-6c89-4135-94f5-14f547e77956
📥 Commits

Reviewing files that changed from the base of the PR and between da099c3 and 861d6250228126ae8336e643b047cc0ce2b4bf14.

📒 Files selected for processing: 4
  • src/renderer/src/lib/resume-sleeping-agent-session-live-ssh-dedupe.test.ts
  • src/renderer/src/lib/resume-sleeping-agent-session.ts
  • src/renderer/src/lib/sleeping-agent-pane-ownership.ts
  • src/renderer/src/lib/sleeping-record-execution-host-scope.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

📝 Walkthrough

The changes update preserved-pane ownership checks for sleeping agent sessions, resolve execution-host scope when comparing provider-session claims, and prevent a session from resuming when a valid, unfinished record in another worktree owns the same provider session. Tests cover SSH connection state, pane bindings, stale worktree IDs, and records associated with different hosts or machines.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 861d6

The change prevents duplicate agent sessions from launching when a sleeping record's session is already owned by another pane or worktree. No concrete merge-blocking risk was identified in the supplied context.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly identifies the main fix: preventing duplicate session wake-ups caused by disconnected SSH panes or stale workspace records.
Description check Passed The description is complete and directly matches the implementation. It covers the user impact, changed behavior, rationale, linked issue reference, visual proof, automated tests, review findings, and…
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

robertnisipeanu and others added 9 commits October 15, 2026 23:27
…panes still own

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…s unreachable

A connected target's live-PTY map is authoritative: sleep kills the PTY but keeps
its id. Cross-worktree session dedupe ignores finished and invalid records, the
same records claim-key dedupe skips.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ng ssh ownership

In a split tab the tab-level pty can belong to another leaf.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…t the focused server

The focus-read ratchet rejects new reads of the routing default; comparing two
records' machines needs only each record's own workspace owner row.
@nwparker
nwparker force-pushed the nwparker/wake-sweep-cross-worktree-claims branch from 8f685d1 to d01252e Compare October 16, 2026 06:29
@nwparker
nwparker merged commit 0321357 into main Oct 16, 2026
24 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants